{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5d493bba-3238-4cc7-9912-2f41edab1bce",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T16:49:33.298984Z",
     "iopub.status.busy": "2022-05-21T16:49:33.298566Z",
     "iopub.status.idle": "2022-05-21T16:49:33.623760Z",
     "shell.execute_reply": "2022-05-21T16:49:33.623022Z",
     "shell.execute_reply.started": "2022-05-21T16:49:33.298892Z"
    }
   },
   "outputs": [],
   "source": [
    "# 导入包\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "413116bc-2702-4e74-aa10-81250d705525",
   "metadata": {},
   "source": [
    "## 一、常用的字符串对象方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d03d80a2-8299-4ca9-94da-4fa810afb249",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:38:31.159346Z",
     "iopub.status.busy": "2022-05-21T17:38:31.159026Z",
     "iopub.status.idle": "2022-05-21T17:38:31.164831Z",
     "shell.execute_reply": "2022-05-21T17:38:31.164172Z",
     "shell.execute_reply.started": "2022-05-21T17:38:31.159321Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b', ' c']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分割字符串\n",
    "\"a;b; c\".split(\";\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e12b3114-845b-4465-ba75-cf2931fe0af6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:38:38.530035Z",
     "iopub.status.busy": "2022-05-21T17:38:38.529714Z",
     "iopub.status.idle": "2022-05-21T17:38:38.535067Z",
     "shell.execute_reply": "2022-05-21T17:38:38.534401Z",
     "shell.execute_reply.started": "2022-05-21T17:38:38.530009Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b', 'c']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分割字符串，删除空白符\n",
    "[x.strip() for x in \"a;b; c\".split(\";\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "15e9fcc7-1320-4d47-832f-3cc42ed8cc59",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:12:06.255186Z",
     "iopub.status.busy": "2022-05-21T17:12:06.254758Z",
     "iopub.status.idle": "2022-05-21T17:12:06.259089Z",
     "shell.execute_reply": "2022-05-21T17:12:06.258535Z",
     "shell.execute_reply.started": "2022-05-21T17:12:06.255168Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a---b---c'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串连接\n",
    "\"a\"+\"---\"+\"b\"+\"---\"+\"c\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "404e7943-5763-47b0-9a42-756d54ac6795",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:13:21.016998Z",
     "iopub.status.busy": "2022-05-21T17:13:21.016699Z",
     "iopub.status.idle": "2022-05-21T17:13:21.021391Z",
     "shell.execute_reply": "2022-05-21T17:13:21.020778Z",
     "shell.execute_reply.started": "2022-05-21T17:13:21.016976Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a---b---c'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串连接\n",
    "\"---\".join([\"a\",\"b\",\"c\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "468aa84e-3f5d-4ecf-87fb-8ef1f8eabf8e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:14:45.698813Z",
     "iopub.status.busy": "2022-05-21T17:14:45.698443Z",
     "iopub.status.idle": "2022-05-21T17:14:45.705243Z",
     "shell.execute_reply": "2022-05-21T17:14:45.704178Z",
     "shell.execute_reply.started": "2022-05-21T17:14:45.698787Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断一个字符串是否在另一个字符串中存在\n",
    "\"c\" in \"abcd\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f2bbc9f1-799e-431b-8db0-edd953961f34",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:16:28.104165Z",
     "iopub.status.busy": "2022-05-21T17:16:28.103629Z",
     "iopub.status.idle": "2022-05-21T17:16:28.109315Z",
     "shell.execute_reply": "2022-05-21T17:16:28.108163Z",
     "shell.execute_reply.started": "2022-05-21T17:16:28.104138Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断一个字符串是否在一个列表中存在\n",
    "\"c\" in [\"a\",\"c\",\"b\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c0b55d93-58d3-42b7-b0e2-4acf58cc7538",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:17:25.669226Z",
     "iopub.status.busy": "2022-05-21T17:17:25.668895Z",
     "iopub.status.idle": "2022-05-21T17:17:25.674179Z",
     "shell.execute_reply": "2022-05-21T17:17:25.673117Z",
     "shell.execute_reply.started": "2022-05-21T17:17:25.669200Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回某个子串第一次出现的的下标，会报错\n",
    "\"a;b; c\".index(\";\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "216708a2-6c21-4e09-a6cc-1243d3c39ac4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:17:45.252411Z",
     "iopub.status.busy": "2022-05-21T17:17:45.252095Z",
     "iopub.status.idle": "2022-05-21T17:17:45.258560Z",
     "shell.execute_reply": "2022-05-21T17:17:45.257242Z",
     "shell.execute_reply.started": "2022-05-21T17:17:45.252386Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查找某个子串第一次出现的的下标，不会报错\n",
    "\"a;b; c\".find(\";\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c0c79652-4f2d-47e7-bbda-33559c1ae289",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-21T17:18:27.979275Z",
     "iopub.status.busy": "2022-05-21T17:18:27.978946Z",
     "iopub.status.idle": "2022-05-21T17:18:27.983883Z",
     "shell.execute_reply": "2022-05-21T17:18:27.983240Z",
     "shell.execute_reply.started": "2022-05-21T17:18:27.979249Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'k;b; c'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 替代字符串\n",
    "\"a;b; c\".replace(\"a\",\"k\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
